package dao

import (
	"GuidingSystem/model/reply"
)

func (db *db) CreateComment(comment reply.Comment) (reply.Comment, error) {
	res := reply.Comment{}
	result := db.DBEngine.Create(&comment)
	if result.Error != nil {
		return res, result.Error
	}
	result.Find(&res)
	return res, nil
}

func (db *db) GetCommentsByCemeteryID(cemeteryID int64) ([]*reply.Comment, error) {
	res := make([]*reply.Comment, 0)
	err := db.DBEngine.Where("cemetery_id = ?", cemeteryID).Find(&res).Error
	return res, err
}

func (db *db) GetCommentByID(id int64) (reply.Comment, error) {
	res := reply.Comment{}
	err := db.DBEngine.Where("id = ?", id).First(&res).Error
	return res, err
}

func (db *db) UpdateComment(params *reply.Comment) error {
	err := db.DBEngine.Model(&reply.Comment{}).Where("id = ?", params.ID).Update(params).Error
	return err
}
